"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GmReqHandler = void 0;
const AccountDailyLogin_1 = require("../account_server/dao/AccountDailyLogin");
const AccountDailyRegister_1 = require("../account_server/dao/AccountDailyRegister");
const AccountDao_1 = require("../account_server/dao/AccountDao");
const UserDao_1 = require("../account_server/dao/UserDao");
const RoomDao_1 = require("../hall_server/dao/RoomDao");
const RoomResultDao_1 = require("../hall_server/dao/RoomResultDao");
const RoomTemplateDao_1 = require("../hall_server/dao/RoomTemplateDao");
const RoomVideoDao_1 = require("../hall_server/dao/RoomVideoDao");
const ClubTopDao_1 = require("../log_server/dao/ClubTopDao");
const Daily_ResourceDao_1 = require("../log_server/dao/Daily_ResourceDao");
const RoomStatisticsDao_1 = require("../log_server/dao/RoomStatisticsDao");
const User_Coins_HistoryDao_1 = require("../log_server/dao/User_Coins_HistoryDao");
const User_Gems_HistoryDao_1 = require("../log_server/dao/User_Gems_HistoryDao");
const User_Meilis_HistoryDao_1 = require("../log_server/dao/User_Meilis_HistoryDao");
const User_Spend_DailyDao_1 = require("../log_server/dao/User_Spend_DailyDao");
const LogServerHelper_1 = require("../log_server/LogServerHelper");
const ChargeDao_1 = require("../pay_server/dao/ChargeDao");
const Config_1 = require("../src/config/Config");
const ErrorCode_1 = require("../src/config/ErrorCode");
const GameConfig_1 = require("../src/config/GameConfig");
const GoodConfig_1 = require("../src/config/GoodConfig");
const ServerConfig_1 = require("../src/config/ServerConfig");
const DateUtil_1 = require("../src/engine/utils/DateUtil");
const Logger_1 = require("../src/engine/utils/Logger");
const Md5Helper_1 = require("../src/engine/utils/Md5Helper");
const WebUtil_1 = require("../src/engine/utils/WebUtil");
const GameImgHelper_1 = require("../src/game/helper/GameImgHelper");
const ResponseModel_1 = require("../src/model/ResponseModel");
const ServerManager_1 = require("../src/server/ServerManager");
const LogCoinDao_1 = require("./dao/LogCoinDao");
const LogGemDao_1 = require("./dao/LogGemDao");
const SystemSettingDao_1 = require("./dao/SystemSettingDao");
const GmUserModel_1 = require("./model/GmUserModel");
const request = require('request');
const crypto = require("crypto");
const multer = require('multer');
const routerMap = {
    login: "/login",
    get_main_statistics_info: "/get_main_statistics_info",
    get_account_list: "/get_account_list",
    search_account: "/search_account",
    get_account_register: "/get_account_register",
    get_account_login: "/get_account_login",
    get_account_keep: "/get_account_keep",
    get_user_list: "/get_user_list",
    get_user_info: "/get_user_info",
    get_user_normal_daili_list: "/get_user_normal_daili_list",
    get_user_qudao_daili_list: "/get_user_qudao_daili_list",
    charge_by_gm: "/charge_by_gm",
    fengjin_user: "/fengjin_user",
    set_normal_daili: "/set_normal_daili",
    set_qudao_daili: "/set_qudao_daili",
    req_invite_list: "/req_invite_list",
    get_log_gem_date: "/get_log_gem_date",
    get_log_gem_week: "/get_log_gem_week",
    get_log_gem_month: "/get_log_gem_month",
    get_log_coin_date: "/get_log_coin_date",
    get_log_coin_week: "/get_log_coin_week",
    get_log_coin_month: "/get_log_coin_month",
    game_date_charge_data: "/game_date_charge_data",
    game_week_charge_data: "/game_week_charge_data",
    game_month_charge_data: "/game_month_charge_data",
    get_user_spend: "/get_user_spend",
    update_system_setting: "/update_system_setting",
    get_system_setting: "/get_system_setting",
    get_notice: "/get_notice",
    get_choushui: "/get_choushui",
    get_gems_detail: "/get_gems_detail",
    get_coins_detail: "/get_coins_detail",
    get_meilis_detail: "/get_meilis_detail",
    get_daily_resource: "/get_daily_resource",
    set_allserver_status: "/set_allserver_status",
    get_gm_server_status: "/get_gm_server_status",
    set_gameserver_status: "/set_gameserver_status",
    get_gameserver_status: "/get_gameserver_status",
    create_ziyou_room_template: "/create_ziyou_room_template",
    get_ziyou_room_template: "/get_ziyou_room_template",
    delete_ziyou_room_template: "/delete_ziyou_room_template",
    clear_weihu_room: "/clear_weihu_room",
    fix_club_top: "/fix_club_top",
    kill_all_users: "/kill_all_users",
    get_zhanji: "/get_zhanji",
    get_zhanji_detail: "/get_zhanji_detail",
    unbind: "/unbind",
    upload_img: "/upload_img",
    get_room_statistics: "/get_room_statistics",
};
class GmReqHandler {
    init(app) {
        for (const key in routerMap) {
            if (routerMap[key] == routerMap.upload_img) {
                app.post(routerMap.upload_img, multer().single('file'), this.on_upload_img.bind(this));
            }
            else {
                app.use(routerMap[key], this.onBaseRoot.bind(this));
            }
        }
    }
    onBaseRoot(req, resp) {
        try {
            let ip = WebUtil_1.WebUtil.getIpByExpressReq(req);
            Logger_1.Logger.log("onBaseRoot=req=", ip, req.baseUrl);
            if (req.baseUrl == routerMap.login) {
                this.checkBody(ip, req, resp, this.on_login.bind(this));
            }
            else if (req.baseUrl == routerMap.set_allserver_status) {
                this.checkBody_md5(ip, req, resp, this.set_allserver_status.bind(this));
            }
            else if (req.baseUrl == routerMap.set_gameserver_status) {
                this.checkBody_md5(ip, req, resp, this.set_gameserver_status.bind(this));
            }
            else if (req.baseUrl == routerMap.get_gameserver_status) {
                this.checkBody_md5(ip, req, resp, this.get_gameserver_status.bind(this));
            }
            else if (req.baseUrl == routerMap.get_gm_server_status) {
                this.checkBody_md5(ip, req, resp, this.get_gm_server_status.bind(this));
            }
            else if (req.baseUrl == routerMap.get_main_statistics_info) {
                this.checkBody_md5(ip, req, resp, this.on_get_main_statistics_info.bind(this));
            }
            else if (req.baseUrl == routerMap.get_account_list) {
                this.checkBody_md5(ip, req, resp, this.on_get_account_list.bind(this));
            }
            else if (req.baseUrl == routerMap.search_account) {
                this.checkBody_md5(ip, req, resp, this.on_search_account.bind(this));
            }
            else if (req.baseUrl == routerMap.get_account_register) {
                this.checkBody_md5(ip, req, resp, this.on_get_account_register.bind(this));
            }
            else if (req.baseUrl == routerMap.get_account_login) {
                this.checkBody_md5(ip, req, resp, this.on_get_account_login.bind(this));
            }
            else if (req.baseUrl == routerMap.get_account_keep) {
                this.checkBody_md5(ip, req, resp, this.on_get_account_keep.bind(this));
            }
            else if (req.baseUrl == routerMap.get_user_list) {
                this.checkBody_md5(ip, req, resp, this.on_get_user_list.bind(this));
            }
            else if (req.baseUrl == routerMap.get_user_normal_daili_list) {
                this.checkBody_md5(ip, req, resp, this.on_get_user_normal_daili_list.bind(this));
            }
            else if (req.baseUrl == routerMap.get_user_qudao_daili_list) {
                this.checkBody_md5(ip, req, resp, this.on_get_user_qudao_daili_list.bind(this));
            }
            else if (req.baseUrl == routerMap.get_user_info) {
                this.checkBody_md5(ip, req, resp, this.on_get_user_info.bind(this));
            }
            else if (req.baseUrl == routerMap.charge_by_gm) {
                this.checkBody_md5(ip, req, resp, this.on_charge_by_gm.bind(this));
            }
            else if (req.baseUrl == routerMap.fengjin_user) {
                this.checkBody_md5(ip, req, resp, this.on_fengjin_user.bind(this));
            }
            else if (req.baseUrl == routerMap.set_normal_daili) {
                this.checkBody_md5(ip, req, resp, this.on_set_normal_daili.bind(this));
            }
            else if (req.baseUrl == routerMap.set_qudao_daili) {
                this.checkBody_md5(ip, req, resp, this.on_set_qudao_daili.bind(this));
            }
            else if (req.baseUrl == routerMap.req_invite_list) {
                this.checkBody_md5(ip, req, resp, this.on_req_invite_list.bind(this));
            }
            else if (req.baseUrl == routerMap.get_log_gem_date) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_gem_date.bind(this));
            }
            else if (req.baseUrl == routerMap.get_log_gem_week) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_gem_week.bind(this));
            }
            else if (req.baseUrl == routerMap.get_log_gem_month) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_gem_month.bind(this));
            }
            else if (req.baseUrl == routerMap.get_log_coin_date) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_coin_date.bind(this));
            }
            else if (req.baseUrl == routerMap.get_log_coin_week) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_coin_week.bind(this));
            }
            else if (req.baseUrl == routerMap.get_log_coin_month) {
                this.checkBody_md5(ip, req, resp, this.on_get_log_coin_month.bind(this));
            }
            else if (req.baseUrl == routerMap.game_date_charge_data) {
                this.checkBody_md5(ip, req, resp, this.on_game_date_charge_data.bind(this));
            }
            else if (req.baseUrl == routerMap.game_week_charge_data) {
                this.checkBody_md5(ip, req, resp, this.on_game_week_charge_data.bind(this));
            }
            else if (req.baseUrl == routerMap.game_month_charge_data) {
                this.checkBody_md5(ip, req, resp, this.on_game_month_charge_data.bind(this));
            }
            else if (req.baseUrl == routerMap.get_user_spend) {
                this.checkBody_md5(ip, req, resp, this.on_get_user_spend.bind(this));
            }
            else if (req.baseUrl == routerMap.get_room_statistics) {
                this.checkBody_md5(ip, req, resp, this.on_get_room_statistics.bind(this));
            }
            else if (req.baseUrl == routerMap.update_system_setting) {
                this.checkBody_md5(ip, req, resp, this.on_update_system_setting.bind(this));
            }
            else if (req.baseUrl == routerMap.get_system_setting) {
                this.checkBody_md5(ip, req, resp, this.on_get_system_setting.bind(this));
            }
            else if (req.baseUrl == routerMap.get_choushui) {
                this.checkBody_md5(ip, req, resp, this.on_get_choushui.bind(this));
            }
            else if (req.baseUrl == routerMap.get_notice) {
                this.checkBody_md5(ip, req, resp, this.on_get_notice.bind(this));
            }
            else if (req.baseUrl == routerMap.get_gems_detail) {
                this.checkBody_md5(ip, req, resp, this.on_get_gems_detail.bind(this));
            }
            else if (req.baseUrl == routerMap.get_coins_detail) {
                this.checkBody_md5(ip, req, resp, this.on_get_coins_detail.bind(this));
            }
            else if (req.baseUrl == routerMap.get_meilis_detail) {
                this.checkBody_md5(ip, req, resp, this.on_get_meilis_detail.bind(this));
            }
            else if (req.baseUrl == routerMap.get_daily_resource) {
                this.checkBody_md5(ip, req, resp, this.on_get_daily_resource.bind(this));
            }
            else if (req.baseUrl == routerMap.create_ziyou_room_template) {
                this.checkBody_md5(ip, req, resp, this.on_create_ziyou_room_template.bind(this));
            }
            else if (req.baseUrl == routerMap.get_ziyou_room_template) {
                this.checkBody_md5(ip, req, resp, this.on_get_ziyou_room_template.bind(this));
            }
            else if (req.baseUrl == routerMap.delete_ziyou_room_template) {
                this.checkBody_md5(ip, req, resp, this.on_delete_ziyou_room_template.bind(this));
            }
            else if (req.baseUrl == routerMap.clear_weihu_room) {
                this.checkBody_md5(ip, req, resp, this.on_clear_weihu_room.bind(this));
            }
            else if (req.baseUrl == routerMap.fix_club_top) {
                this.checkBody_md5(ip, req, resp, this.fix_club_top.bind(this));
            }
            else if (req.baseUrl == routerMap.kill_all_users) {
                this.checkBody_md5(ip, req, resp, this.kill_all_users.bind(this));
            }
            else if (req.baseUrl == routerMap.get_zhanji) {
                this.checkBody_md5(ip, req, resp, this.get_zhanji.bind(this));
            }
            else if (req.baseUrl == routerMap.get_zhanji_detail) {
                this.checkBody_md5(ip, req, resp, this.get_zhanji_detail.bind(this));
            }
            else if (req.baseUrl == routerMap.unbind) {
                this.checkBody_md5(ip, req, resp, this.on_unbind.bind(this));
            }
        }
        catch (error) {
            Logger_1.Logger.warn("onBaseRoot error", error);
        }
    }
    checkBody(ip, req, resp, callback) {
        if (req.body) {
            try {
                let jsonObj = JSON.parse(req.body);
                callback && callback(req, resp, jsonObj, ip);
            }
            catch (error) {
                Logger_1.Logger.error("收到非法Http请求body", ip, req.body, error);
                resp.end();
            }
        }
        else {
            resp.end();
        }
    }
    checkBody_md5(ip, req, resp, callback) {
        if (req.body) {
            try {
                let jsonObj = JSON.parse(req.body);
                let k = jsonObj["k"];
                let data = jsonObj["data"];
                if (k == Md5Helper_1.Md5Helper.getMd5_encrypt(JSON.stringify(data))) {
                    let user = this.checkToken(data["token"], resp);
                    if (user) {
                        callback && callback(req, resp, data, ip, user);
                    }
                }
                else {
                    Logger_1.Logger.warn("收到非法Http请求 key", ip, req.body);
                    resp.end();
                }
            }
            catch (error) {
                Logger_1.Logger.warn("收到非法Http请求body", ip, req.body, error);
                resp.end();
            }
        }
        else {
            resp.end();
        }
    }
    checkToken(token, resp, req = null) {
        let user = GmUserModel_1.GmUserModel.getUserByToken(token);
        if (user) {
            return user;
        }
        let respModel = new ResponseModel_1.ResponseModel();
        respModel.code = ErrorCode_1.ErrorCode.Code.LoginError_token;
        respModel.msg = "token已过期";
        resp.end(JSON.stringify(respModel));
        return null;
    }
    on_upload_img(req, resp, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            Logger_1.Logger.log("on_upload_img==", req);
            let token = req.query["token"];
            if (this.checkToken(token, resp, req)) {
                let respModel = new ResponseModel_1.ResponseModel();
                let userid = req.query["userid"];
                if (req.file) {
                    let buffer = req.file.buffer;
                    let uploadType = GameConfig_1.GameConfig.upload_pic_type.Img1;
                    let imgurl = GameImgHelper_1.GameImgHelper.buffer_to_imgurl(userid, uploadType, buffer);
                    // respModel = await HallServer_SocketMsgHandler.saveUploadImg(imgurl, uploadType, userid, GameConfig.Account_Type.Account)
                    if (respModel.code == ErrorCode_1.ErrorCode.Code.Suc) {
                        ServerManager_1.ServerManager.instance.notify_update_img(userid, imgurl, uploadType);
                    }
                }
                else {
                    respModel.code = ErrorCode_1.ErrorCode.Code.Fail;
                    respModel.msg = "不存在上传文件";
                }
                resp.end(JSON.stringify(respModel));
            }
        });
    }
    /**
     * @param req 用户登录
     * @param resp
     * @param data
     * @param ip
     */
    on_login(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            // Logger.log("onLogin==", req, ip, req.query, req.body)
            let userName = data["userName"];
            let pass = data["pass"];
            let respModel = yield GmUserModel_1.GmUserModel.checkLogin(userName, pass);
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_main_statistics_info(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            Logger_1.Logger.log("on_get_main_statistics_info==", data, ip);
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = yield UserDao_1.UserDao.get_main_statistics_info();
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_account_list(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let pagenum = data["pagenum"];
            let pagesize = data["pagesize"];
            let respModel = new ResponseModel_1.ResponseModel();
            let resultObj = {};
            resultObj["accounts"] = yield AccountDao_1.AccountDao.get_account_list(pagenum, pagesize);
            resultObj["count"] = yield AccountDao_1.AccountDao.getAccountNum();
            respModel.data = resultObj;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_search_account(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchKey = data["searchKey"];
            let searchValue = data["searchValue"];
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = yield AccountDao_1.AccountDao.search_account(searchKey, searchValue);
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_account_register(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let startDate = data["startDate"];
            let endDate = data["endDate"];
            let respModel = new ResponseModel_1.ResponseModel();
            let startDateStr = DateUtil_1.default.formatDateStr3(startDate);
            let endDateStr = DateUtil_1.default.formatDateStr3(endDate);
            let list = yield AccountDailyRegister_1.AccountDailyRegister.getAccountRegister(startDateStr, endDateStr);
            let totalDay = Math.floor((endDate - startDate) / Config_1.Config.OneDay) + 1;
            let resultList = [];
            for (let i = 0; i < totalDay; i++) {
                let defaultTime = new Date(startDate);
                defaultTime.setHours(0);
                defaultTime.setMinutes(0);
                defaultTime.setSeconds(0);
                let obj = {
                    "date": DateUtil_1.default.formatDateStr3(defaultTime.getTime() + Config_1.Config.OneDay * i)
                };
                let count = 0;
                for (let mm = 0; mm < list.length; mm++) {
                    let date_stampDate = new Date(list[mm]["date"]);
                    if (DateUtil_1.default.formatDateStr3(date_stampDate.getTime()) == obj["date"]) {
                        count++;
                    }
                }
                obj["count"] = count;
                resultList[i] = obj;
            }
            respModel.data = resultList;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_account_login(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let startDate = data["startDate"];
            let endDate = data["endDate"];
            let respModel = new ResponseModel_1.ResponseModel();
            let startDateStr = DateUtil_1.default.formatDateStr3(startDate);
            let endDateStr = DateUtil_1.default.formatDateStr3(endDate);
            let list = yield AccountDailyLogin_1.AccountDailyLogin.getAccountLogin(startDateStr, endDateStr);
            let totalDay = Math.floor((endDate - startDate) / Config_1.Config.OneDay) + 1;
            let resultList = [];
            for (let i = 0; i < totalDay; i++) {
                let defaultTime = new Date(startDate);
                defaultTime.setHours(0);
                defaultTime.setMinutes(0);
                defaultTime.setSeconds(0);
                let obj = {
                    "date": DateUtil_1.default.formatDateStr3(defaultTime.getTime() + Config_1.Config.OneDay * i)
                };
                let count = 0;
                for (let mm = 0; mm < list.length; mm++) {
                    let date_stampDate = new Date(list[mm]["date"]);
                    if (DateUtil_1.default.formatDateStr3(date_stampDate.getTime()) == obj["date"]) {
                        count++;
                    }
                }
                obj["count"] = count;
                resultList[i] = obj;
            }
            respModel.data = resultList;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_account_keep(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchTime = data["searchTime"];
            let totalDay = Math.floor((searchTime[1] - searchTime[0]) / Config_1.Config.OneDay) + 1;
            let searchLoginStartTime = Math.floor(searchTime[0]);
            let searchLoginEndTime = Math.floor(searchTime[1] + Config_1.Config.OneDay * 30);
            let startTimeStr = DateUtil_1.default.formatDateStr3(searchTime[0]);
            let endTimeStr = DateUtil_1.default.formatDateStr3(searchTime[1]);
            let loginList = yield AccountDailyLogin_1.AccountDailyLogin.getAccountLogin(DateUtil_1.default.formatDateStr3(searchLoginStartTime), DateUtil_1.default.formatDateStr3(searchLoginEndTime));
            let registerList = yield AccountDailyRegister_1.AccountDailyRegister.getAccountRegister(startTimeStr, endTimeStr);
            let resultList = [];
            for (let i = 0; i < totalDay; i++) {
                let defaultTime = new Date(searchTime[1]);
                defaultTime.getDate();
                defaultTime.setHours(0);
                defaultTime.setMinutes(0);
                defaultTime.setSeconds(0);
                let obj = {
                    "date": DateUtil_1.default.formatDateStr3(defaultTime.getTime() - i * Config_1.Config.OneDay)
                };
                let registerNum = 0;
                let keepuser2 = 0;
                let keepuser3 = 0;
                let keepuser5 = 0;
                let keepuser7 = 0;
                let keepuser10 = 0;
                let keepuser15 = 0;
                let keepuser30 = 0;
                let keepuser60 = 0;
                for (let mm = 0; mm < registerList.length; mm++) {
                    let registerObj = registerList[mm];
                    let date_stampDate = new Date(registerObj["date"]);
                    if (obj["date"] == DateUtil_1.default.formatDateStr3(date_stampDate.getTime())) {
                        registerNum++;
                        let date2 = (obj["date"] + Config_1.Config.OneDay);
                        let date3 = (obj["date"] + Config_1.Config.OneDay * 2);
                        let date5 = (obj["date"] + Config_1.Config.OneDay * 4);
                        let date7 = (obj["date"] + Config_1.Config.OneDay * 6);
                        let date10 = (obj["date"] + Config_1.Config.OneDay * 9);
                        let date15 = (obj["date"] + Config_1.Config.OneDay * 14);
                        let date30 = (obj["date"] + Config_1.Config.OneDay * 29);
                        let date60 = (obj["date"] + Config_1.Config.OneDay * 59);
                        for (let nn = 0; nn < loginList.length; nn++) {
                            let obj = loginList[nn];
                            let date_stampDate = new Date(obj["date_stamp"]);
                            if (Math.floor(date_stampDate.getTime()) == Math.floor(date2) && registerObj["user_id"] == obj["user_id"]) {
                                keepuser2++;
                            }
                            if (Math.floor(date_stampDate.getTime()) == Math.floor(date3) && registerObj["user_id"] == obj["user_id"]) {
                                keepuser3++;
                            }
                            if (Math.floor(date_stampDate.getTime()) == Math.floor(date5) && registerObj["user_id"] == obj["user_id"]) {
                                keepuser5++;
                            }
                            if (Math.floor(date_stampDate.getTime()) == Math.floor(date7) && registerObj["user_id"] == obj["user_id"]) {
                                keepuser7++;
                            }
                            if (Math.floor(date_stampDate.getTime()) == Math.floor(date10) && registerObj["user_id"] == obj["user_id"]) {
                                keepuser10++;
                            }
                            if (Math.floor(date_stampDate.getTime()) == Math.floor(date15) && registerObj["user_id"] == obj["user_id"]) {
                                keepuser15++;
                            }
                            if (Math.floor(date_stampDate.getTime()) == Math.floor(date30) && registerObj["user_id"] == obj["user_id"]) {
                                keepuser30++;
                            }
                            if (Math.floor(date_stampDate.getTime()) == Math.floor(date60) && registerObj["user_id"] == obj["user_id"]) {
                                keepuser60++;
                            }
                        }
                    }
                }
                obj["registerNum"] = registerNum;
                obj["keepuser2"] = keepuser2;
                obj["keepuser3"] = keepuser3;
                obj["keepuser5"] = keepuser5;
                obj["keepuser7"] = keepuser7;
                obj["keepuser10"] = keepuser10;
                obj["keepuser15"] = keepuser15;
                obj["keepuser30"] = keepuser30;
                obj["keepuser60"] = keepuser60;
                resultList.push(obj);
            }
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = resultList;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_user_list(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let pagenum = data["pagenum"];
            let pagesize = data["pagesize"];
            let respModel = new ResponseModel_1.ResponseModel();
            let resultObj = {};
            resultObj["users"] = yield UserDao_1.UserDao.get_user_list(pagenum, pagesize);
            resultObj["count"] = yield UserDao_1.UserDao.getUserNum();
            respModel.data = resultObj;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_user_normal_daili_list(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let pagenum = data["pagenum"];
            let pagesize = data["pagesize"];
            let respModel = new ResponseModel_1.ResponseModel();
            let resultObj = {};
            let users = yield UserDao_1.UserDao.get_user_normal_daili_list(pagenum, pagesize);
            for (let i = 0; i < users.length; i++) {
                let count = yield UserDao_1.UserDao.get_normal_daili_xiaji_num(users[i]["userid"]);
                users[i]["xiaji"] = count;
            }
            resultObj["users"] = users;
            resultObj["count"] = yield UserDao_1.UserDao.get_user_normal_daili_count();
            respModel.data = resultObj;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_user_qudao_daili_list(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let pagenum = data["pagenum"];
            let pagesize = data["pagesize"];
            let respModel = new ResponseModel_1.ResponseModel();
            let resultObj = {};
            let users = yield UserDao_1.UserDao.get_user_qudao_daili_list(pagenum, pagesize);
            for (let i = 0; i < users.length; i++) {
                let count = yield UserDao_1.UserDao.get_normal_daili_xiaji_num(users[i]["userid"]);
                users[i]["xiaji"] = count;
            }
            resultObj["users"] = users;
            resultObj["count"] = yield UserDao_1.UserDao.get_user_qudao_daili_count();
            respModel.data = resultObj;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_user_info(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let userid = data["userid"];
            let respModel = new ResponseModel_1.ResponseModel();
            let user = yield UserDao_1.UserDao.get_user_data_by_userid(userid);
            let resultObj = {};
            if (user) {
                resultObj["users"] = [user];
            }
            else {
                resultObj["users"] = [];
            }
            respModel.data = resultObj;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_charge_by_gm(req, resp, data, ip, user) {
        return __awaiter(this, void 0, void 0, function* () {
            let userid = data["userid"];
            let num = data["num"];
            let type = data["type"];
            if (type == "gems") {
                let left_gems = yield UserDao_1.UserDao.addGems(userid, num);
                ServerManager_1.ServerManager.instance.notify_update_gems(userid);
                LogGemDao_1.LogGemDao.add_user_gems_log(userid, num, user.userName, DateUtil_1.default.formatDateStr(DateUtil_1.default.now()), user.userName + "在管理后台增加了" + num + "钻石");
                LogServerHelper_1.LogServerHelper.log_add_user_gems_history(userid, num, left_gems, GameConfig_1.GameConfig.Gems_History_Reason.Gm_Add, user.userName + "在管理后台增加了" + num + "钻石");
            }
            else if (type == "coins") {
                let left_coins = yield UserDao_1.UserDao.addCoins(userid, num);
                ServerManager_1.ServerManager.instance.notify_update_coins(userid);
                LogCoinDao_1.LogCoinDao.add_user_coin_log(userid, num, user.userName, DateUtil_1.default.formatDateStr(DateUtil_1.default.now()), user.userName + "在管理后台增加了" + num + "金豆");
                LogServerHelper_1.LogServerHelper.log_add_user_coins_history(userid, num, left_coins, GameConfig_1.GameConfig.Coins_History_Reason.Gm_Add, user.userName + "在管理后台增加了" + num + "金豆");
            }
            // else if (type == "meilis") {
            //     let left_meili: number = await UserDao.addMeili(userid, num)
            //     ServerManager.instance.notify_update_meili(userid)
            //     LogServerHelper.log_add_user_meilis_history(userid, num, left_meili, GameConfig.Meilis_History_Reason.Gm_Add, user.userName + "在管理后台增加了" + num + "魅力值")
            // }
            // else if (type == "income") {
            //     let left_income: number = await UserDao.add_income(userid, num)
            //     ServerManager.instance.notify_update_income(userid)
            //     LogServerHelper.log_add_user_income_history(userid, num, left_income, GameConfig.Income_History_Reason.Gm_Add, user.userName + "在管理后台增加了" + num + "未兑换金豆")
            // }
            let respModel = new ResponseModel_1.ResponseModel();
            resp.end(JSON.stringify(respModel));
        });
    }
    on_fengjin_user(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let userid = data["userid"];
            let state = data["state"];
            yield UserDao_1.UserDao.setState(userid, state);
            let respModel = new ResponseModel_1.ResponseModel();
            resp.end(JSON.stringify(respModel));
        });
    }
    on_set_normal_daili(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let userid = data["userid"];
            let lv = data["lv"];
            yield UserDao_1.UserDao.set_lv(userid, lv);
            yield UserDao_1.UserDao.clearInvite(userid);
            let respModel = new ResponseModel_1.ResponseModel();
            resp.end(JSON.stringify(respModel));
        });
    }
    on_set_qudao_daili(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let userid = data["userid"];
            let qudaodaili = data["qudaodaili"];
            yield UserDao_1.UserDao.set_qudaodaili(userid, qudaodaili);
            let respModel = new ResponseModel_1.ResponseModel();
            resp.end(JSON.stringify(respModel));
        });
    }
    on_req_invite_list(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
        });
    }
    on_get_log_gem_date(req, resp, data, ip, user) {
        return __awaiter(this, void 0, void 0, function* () {
            let startTime = data["startTime"];
            let endTime = data["endTime"];
            let startTimeStr = DateUtil_1.default.formatDateStr(startTime);
            let endTimeStr = DateUtil_1.default.formatDateStr(endTime);
            let list = yield LogGemDao_1.LogGemDao.get_log_gem(startTimeStr, endTimeStr);
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = list;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_log_gem_week(req, resp, data, ip, user) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchDate = data["searchDate"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 7);
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
            let list = yield LogGemDao_1.LogGemDao.get_log_gem(startTime, endTime);
            let resultList = [];
            let dateArr = [];
            for (let i = 0; i < 7; i++) {
                tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i);
                let tempDateStr = DateUtil_1.default.formatDateStr3(tempDate.getTime());
                let obj = {
                    "date": tempDateStr,
                    "gems": 0,
                };
                resultList[i] = obj;
                dateArr[i] = tempDateStr;
            }
            for (let j = 0; j < list.length; j++) {
                let data = list[j];
                let tempDateStr = DateUtil_1.default.formatDateStr3(new Date(data["time"]).getTime());
                let index = dateArr.indexOf(tempDateStr);
                if (index != -1) {
                    let obj = resultList[index];
                    obj["gems"] += data["gems"];
                }
            }
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = resultList;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_log_gem_month(req, resp, data, ip, user) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchDate = data["searchDate"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let endDate;
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let resultList = [];
            let dateArr = [];
            for (let i = 0; i < 31; i++) {
                tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i);
                if (tempDate.getMonth() == startDate.getMonth()) {
                    endDate = tempDate;
                    let tempDateStr = DateUtil_1.default.formatDateStr3(tempDate.getTime());
                    let obj = {
                        "date": tempDateStr,
                        "gems": 0,
                    };
                    resultList[i] = obj;
                    dateArr[i] = tempDateStr;
                }
                else {
                    break;
                }
            }
            let endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
            let list = yield LogGemDao_1.LogGemDao.get_log_gem(startTime, endTime);
            for (let j = 0; j < list.length; j++) {
                let data = list[j];
                let tempDateStr = DateUtil_1.default.formatDateStr3(new Date(data["time"]).getTime());
                let index = dateArr.indexOf(tempDateStr);
                if (index != -1) {
                    let obj = resultList[index];
                    obj["gems"] += data["gems"];
                }
            }
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = resultList;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_log_coin_date(req, resp, data, ip, user) {
        return __awaiter(this, void 0, void 0, function* () {
            let startTime = data["startTime"];
            let endTime = data["endTime"];
            let startTimeStr = DateUtil_1.default.formatDateStr(startTime);
            let endTimeStr = DateUtil_1.default.formatDateStr(endTime);
            let list = yield LogCoinDao_1.LogCoinDao.get_log_coin(startTimeStr, endTimeStr);
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = list;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_log_coin_week(req, resp, data, ip, user) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchDate = data["searchDate"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 7);
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
            let list = yield LogCoinDao_1.LogCoinDao.get_log_coin(startTime, endTime);
            let resultList = [];
            let dateArr = [];
            for (let i = 0; i < 7; i++) {
                tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i);
                let tempDateStr = DateUtil_1.default.formatDateStr3(tempDate.getTime());
                let obj = {
                    "date": tempDateStr,
                    "coin": 0,
                };
                resultList[i] = obj;
                dateArr[i] = tempDateStr;
            }
            for (let j = 0; j < list.length; j++) {
                let data = list[j];
                let tempDateStr = DateUtil_1.default.formatDateStr3(new Date(data["time"]).getTime());
                let index = dateArr.indexOf(tempDateStr);
                if (index != -1) {
                    let obj = resultList[index];
                    obj["coin"] += data["coin"];
                }
            }
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = resultList;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_log_coin_month(req, resp, data, ip, user) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchDate = data["searchDate"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let endDate;
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let resultList = [];
            let dateArr = [];
            for (let i = 0; i < 31; i++) {
                tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i);
                if (tempDate.getMonth() == startDate.getMonth()) {
                    endDate = tempDate;
                    let tempDateStr = DateUtil_1.default.formatDateStr3(tempDate.getTime());
                    let obj = {
                        "date": tempDateStr,
                        "coin": 0,
                    };
                    resultList[i] = obj;
                    dateArr[i] = tempDateStr;
                }
                else {
                    break;
                }
            }
            let endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
            let list = yield LogCoinDao_1.LogCoinDao.get_log_coin(startTime, endTime);
            for (let j = 0; j < list.length; j++) {
                let data = list[j];
                let tempDateStr = DateUtil_1.default.formatDateStr3(new Date(data["time"]).getTime());
                let index = dateArr.indexOf(tempDateStr);
                if (index != -1) {
                    let obj = resultList[index];
                    obj["coin"] += data["coin"];
                }
            }
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = resultList;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_game_date_charge_data(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchDate = data["searchDate"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1);
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
            let list = yield ChargeDao_1.ChargeDao.game_date_charge_data(startTime, endTime);
            for (let i = 0; i < list.length; i++) {
                let item = list[i];
                if (item["type"] == GoodConfig_1.GoodConfig.GoodAddType.gems) {
                    item["gems"] = item["chargenum"];
                    item["coins"] = 0;
                }
                else {
                    item["gems"] = 0;
                    item["coins"] = item["chargenum"];
                }
            }
            Logger_1.Logger.log("on_game_date_charge_data===", searchDate, list);
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = list;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_game_week_charge_data(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchDate = data["searchDate"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 7);
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
            let list = yield ChargeDao_1.ChargeDao.game_week_charge_data(startTime, endTime);
            let resultList = [];
            let dateArr = [];
            for (let i = 0; i < 7; i++) {
                tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i);
                let tempDateStr = DateUtil_1.default.formatDateStr3(tempDate.getTime());
                let obj = {
                    "date": tempDateStr,
                    "rmb": 0,
                    "gems": 0,
                    "coins": 0,
                };
                resultList[i] = obj;
                dateArr[i] = tempDateStr;
            }
            for (let j = 0; j < list.length; j++) {
                let data = list[j];
                let tempDateStr = DateUtil_1.default.formatDateStr3(new Date(data["pay_time"]).getTime());
                let index = dateArr.indexOf(tempDateStr);
                if (index != -1) {
                    let obj = resultList[index];
                    obj["rmb"] += data["rmb"];
                    if (data["type"] == GoodConfig_1.GoodConfig.GoodAddType.gems) {
                        obj["gems"] += data["chargenum"];
                    }
                    else {
                        obj["coins"] += data["chargenum"];
                    }
                }
            }
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = resultList;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_game_month_charge_data(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchDate = data["searchDate"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let endDate;
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let resultList = [];
            let dateArr = [];
            for (let i = 0; i < 31; i++) {
                tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i);
                if (tempDate.getMonth() == startDate.getMonth()) {
                    endDate = tempDate;
                    let tempDateStr = DateUtil_1.default.formatDateStr3(tempDate.getTime());
                    let obj = {
                        "date": tempDateStr,
                        "rmb": 0,
                        "gems": 0,
                        "coins": 0,
                    };
                    resultList[i] = obj;
                    dateArr[i] = tempDateStr;
                }
                else {
                    break;
                }
            }
            let endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
            let list = yield ChargeDao_1.ChargeDao.game_week_charge_data(startTime, endTime);
            for (let j = 0; j < list.length; j++) {
                let data = list[j];
                let tempDateStr = DateUtil_1.default.formatDateStr3(new Date(data["pay_time"]).getTime());
                let index = dateArr.indexOf(tempDateStr);
                if (index != -1) {
                    let obj = resultList[index];
                    obj["rmb"] += data["rmb"];
                    if (data["type"] == GoodConfig_1.GoodConfig.GoodAddType.gems) {
                        obj["gems"] += data["chargenum"];
                    }
                    else {
                        obj["coins"] += data["chargenum"];
                    }
                }
            }
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = resultList;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_user_spend(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let respModel = new ResponseModel_1.ResponseModel();
            let searchDate = data["searchDate"];
            let timetype = data["timetype"];
            let kind = data["kind"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let endDate;
            let endTime;
            let list;
            let resultList = [];
            let dateArr = [];
            if (timetype == "date") {
                endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1);
                endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
                list = yield User_Spend_DailyDao_1.User_Spend_DailyDao.get_user_spend_daily(kind, startTime, endTime);
                Logger_1.Logger.log("on_get_user_spend========", list);
                respModel.data = list;
            }
            else if (timetype == "week" || timetype == "month") {
                if (timetype == "week") {
                    endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 7);
                    for (let i = 0; i < 7; i++) {
                        tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i);
                        let tempDateStr = DateUtil_1.default.formatDateStr3(tempDate.getTime());
                        let obj = {
                            "date": tempDateStr,
                            "gems": 0,
                            "coins": 0,
                        };
                        resultList[i] = obj;
                        dateArr[i] = tempDateStr;
                    }
                }
                else {
                    for (let i = 0; i < 31; i++) {
                        tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i);
                        if (tempDate.getMonth() == startDate.getMonth()) {
                            endDate = tempDate;
                            let tempDateStr = DateUtil_1.default.formatDateStr3(tempDate.getTime());
                            let obj = {
                                "date": tempDateStr,
                                "gems": 0,
                                "coins": 0,
                            };
                            resultList[i] = obj;
                            dateArr[i] = tempDateStr;
                        }
                        else {
                            break;
                        }
                    }
                }
                endTime = DateUtil_1.default.formatDateStr(endDate.getTime()) + Config_1.Config.OneDay;
                list = yield User_Spend_DailyDao_1.User_Spend_DailyDao.get_user_spend_by_date(startTime, endTime);
                for (let j = 0; j < list.length; j++) {
                    let data = list[j];
                    let tempDateStr = DateUtil_1.default.formatDateStr3(new Date(data["date"]).getTime());
                    let index = dateArr.indexOf(tempDateStr);
                    if (index != -1) {
                        let obj = resultList[index];
                        obj["gems"] += data["gems"];
                        obj["coins"] += data["coins"];
                    }
                }
                respModel.data = resultList;
            }
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_room_statistics(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let respModel = new ResponseModel_1.ResponseModel();
            let searchDate = data["searchDate"];
            let timetype = data["timetype"];
            let clubid = data["clubid"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let endDate;
            let endTime;
            let list;
            let resultList = [];
            let dateArr = [];
            if (timetype == "date") {
                endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1);
                endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
                list = yield RoomStatisticsDao_1.RoomStatisticsDao.get_statistics(clubid, startTime, endTime);
                respModel.data = list;
            }
            else if (timetype == "week" || timetype == "month") {
                if (timetype == "week") {
                    endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 7);
                    for (let i = 0; i < 7; i++) {
                        tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i);
                        let tempDateStr = DateUtil_1.default.formatDateStr3(tempDate.getTime());
                        let obj = {
                            "date": tempDateStr,
                            "ju": 0,
                        };
                        resultList[i] = obj;
                        dateArr[i] = tempDateStr;
                    }
                }
                else {
                    for (let i = 0; i < 31; i++) {
                        tempDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + i);
                        if (tempDate.getMonth() == startDate.getMonth()) {
                            endDate = tempDate;
                            let tempDateStr = DateUtil_1.default.formatDateStr3(tempDate.getTime());
                            let obj = {
                                "date": tempDateStr,
                                "ju": 0,
                            };
                            resultList[i] = obj;
                            dateArr[i] = tempDateStr;
                        }
                        else {
                            break;
                        }
                    }
                }
                endTime = DateUtil_1.default.formatDateStr(endDate.getTime()) + Config_1.Config.OneDay;
                list = yield RoomStatisticsDao_1.RoomStatisticsDao.get_statistics(clubid, startTime, endTime);
                for (let j = 0; j < list.length; j++) {
                    let data = list[j];
                    let tempDateStr = DateUtil_1.default.formatDateStr3(new Date(data["time"]).getTime());
                    let index = dateArr.indexOf(tempDateStr);
                    if (index != -1) {
                        let obj = resultList[index];
                        obj["ju"] += 1;
                    }
                }
                respModel.data = resultList;
            }
            resp.end(JSON.stringify(respModel));
        });
    }
    on_update_system_setting(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let setting_key = data["setting_key"];
            let setting_value = data["setting_value"];
            let specailList = GameConfig_1.GameConfig.specialList;
        });
    }
    on_get_system_setting(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let setting_key = data["setting_key"];
            let setting_value = yield SystemSettingDao_1.SystemSettingDao.get_system_setting(setting_key);
            let specailList = GameConfig_1.GameConfig.specialList;
        });
    }
    on_get_notice(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let notice = yield SystemSettingDao_1.SystemSettingDao.get_notice();
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = notice;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_choushui(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let choushui = yield SystemSettingDao_1.SystemSettingDao.get_choushui();
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = choushui;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_gems_detail(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchDate = data["searchDate"];
            let pagenum = data["pagenum"];
            let pagesize = data["pagesize"];
            let userid = data["userid"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1);
            let endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
            let respModel = yield User_Gems_HistoryDao_1.User_Gems_HistoryDao.get_gems_detail(pagenum, pagesize, userid, startTime, endTime);
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_coins_detail(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchDate = data["searchDate"];
            let pagenum = data["pagenum"];
            let pagesize = data["pagesize"];
            let userid = data["userid"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1);
            let endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
            let respModel = yield User_Coins_HistoryDao_1.User_Coins_HistoryDao.get_coins_detail(pagenum, pagesize, userid, startTime, endTime);
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_meilis_detail(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let searchDate = data["searchDate"];
            let pagenum = data["pagenum"];
            let pagesize = data["pagesize"];
            let userid = data["userid"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let startTime = DateUtil_1.default.formatDateStr(startDate.getTime());
            let endDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() + 1);
            let endTime = DateUtil_1.default.formatDateStr(endDate.getTime());
            let respModel = yield User_Meilis_HistoryDao_1.User_Meilis_HistoryDao.get_meilis_detail(pagenum, pagesize, userid, startTime, endTime);
            resp.end(JSON.stringify(respModel));
        });
    }
    on_get_daily_resource(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let resultList = yield Daily_ResourceDao_1.Daily_ResourceDao.get_daily_resource();
            let respModel = new ResponseModel_1.ResponseModel();
            respModel.data = resultList;
            resp.end(JSON.stringify(respModel));
        });
    }
    set_allserver_status(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let status = data["status"];
            ServerConfig_1.ServerConfig.nowServerConfig.status = status;
            ServerManager_1.ServerManager.instance.set_allserver_status(status);
            let respModel = new ResponseModel_1.ResponseModel();
            resp.end(JSON.stringify(respModel));
        });
    }
    set_gameserver_status(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let gameType = data["gameType"];
            let status = data["status"];
            let respModel = new ResponseModel_1.ResponseModel();
            resp.end(JSON.stringify(respModel));
        });
    }
    get_gameserver_status(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let gameType = data["gameType"];
            // let status: number = 0
            // let server: ServerConfig
            // if (gameType == GameConfig.Game_Type.huanghua_mj) {
            //     server = ServerConfig.huanghua_mj_server_list[0]
            // }
            // else if (gameType == GameConfig.Game_Type.ddz) {
            //     server = ServerConfig.ddz_server_list[0]
            // }
            // else if (gameType == GameConfig.Game_Type.jianziding) {
            //     server = ServerConfig.jianziding_server_list[0]
            // }
            // else if (gameType == GameConfig.Game_Type.cangxian_mj) {
            //     server = ServerConfig.cangxian_mj_server_list[0]
            // }
            // else if (gameType == GameConfig.Game_Type.paodekuai) {
            //     server = ServerConfig.paodekuai_server_list[0]
            // }
            // else if (gameType == GameConfig.Game_Type.dazhonger_mj) {
            //     server = ServerConfig.dazhonger_mj_server_list[0]
            // }
            // let respModel: ResponseModel = new ResponseModel()
            // respModel.data = server.status
            // resp.end(JSON.stringify(respModel));
        });
    }
    get_gm_server_status(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let respModel = new ResponseModel_1.ResponseModel();
            let arr = [
                ServerConfig_1.ServerConfig.nowServerConfig.status,
                // ServerConfig.huanghua_mj_server_list[0].status,
                // ServerConfig.ddz_server_list[0].status,
                // ServerConfig.jianziding_server_list[0].status,
                // ServerConfig.cangxian_mj_server_list[0].status,
                // ServerConfig.paodekuai_server_list[0].status,
                // ServerConfig.dazhonger_mj_server_list[0].status,
            ];
            respModel.data = arr;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_create_ziyou_room_template(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let roomObj = data["roomObj"];
            let respModel = new ResponseModel_1.ResponseModel();
            let gameType = roomObj["gameType"];
            let level = roomObj["level"];
            // let roomJinbiConfig: RoomJinbiConfig = RoomJinbiConfig.getConfigByGameAndLevel(gameType, RoomConfig.Room_Type.Ziyou, level)
            // roomObj["enterMin"] = roomJinbiConfig.enterMin
            // roomObj["cost"] = roomJinbiConfig.serve
            // roomObj["difen"] = roomJinbiConfig.difen
            // roomObj["minCharge"] = roomJinbiConfig.minCharge
            // let serverConfig: ServerConfig = ServerConfig.randomGameServer(gameType)
            // let roomModel: RoomModel = new RoomModel();
            // roomModel.roomType = RoomConfig.Room_Type.Ziyou
            // roomModel.room_id = RoomModel.generateRoomId()
            // roomModel.creator = 0 //gm创建
            // roomModel.create_time = DateUtil.now()
            // roomModel.state = RoomConfig.Room_State_Type.Normal
            // roomModel.gameType = gameType;
            // roomModel.server_id = serverConfig.id;
            // roomModel.conf = roomObj
            // roomModel.game_info.game_state = 0
            // let dbSuc: boolean = await RoomTemplateDao.insert_room_template(roomObj["name"], 0, 0, roomObj, RoomConfig.Room_Type.Ziyou)
            // if (dbSuc) {
            //     ServerManager.instance.insertRoomTemplateModel()
            //     respModel.code = ErrorCode.Code.Suc
            // } else {
            //     respModel.code = ErrorCode.Code.Db_Error
            //     respModel.msg = "插入房间模板时出错"
            // }
            // resp.end(JSON.stringify(respModel));
        });
    }
    on_get_ziyou_room_template(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let gameType = data["gameType"];
            let respModel = new ResponseModel_1.ResponseModel();
            let resultList = [];
            let roomObjList = yield RoomTemplateDao_1.RoomTemplateDao.get_ziyou_room_template(gameType);
            for (let i = 0; i < roomObjList.length; i++) {
                // let room: RoomTemplateModel = RoomTemplateModel.initOneRoomTemplate(roomObjList[i])
                // resultList.push(room)
            }
            respModel.data = resultList;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_delete_ziyou_room_template(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let id = data["id"];
            let respModel = new ResponseModel_1.ResponseModel();
            let dbSuc = yield RoomTemplateDao_1.RoomTemplateDao.delete_room_template(id);
            if (dbSuc) {
                ServerManager_1.ServerManager.instance.deleteRoomTemplate(id);
            }
            else {
                respModel.code = ErrorCode_1.ErrorCode.Code.Fail;
                respModel.msg = "删除失败";
            }
            resp.end(JSON.stringify(respModel));
        });
    }
    on_clear_weihu_room(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let respModel = new ResponseModel_1.ResponseModel();
            let dbSuc = yield RoomDao_1.RoomDao.clear_all_room();
            if (dbSuc) {
            }
            else {
                respModel.code = ErrorCode_1.ErrorCode.Code.Fail;
                respModel.msg = "清理失败";
            }
            resp.end(JSON.stringify(respModel));
        });
    }
    fix_club_top(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let respModel = new ResponseModel_1.ResponseModel();
            let clubid = data["clubid"];
            let userid = data["userid"];
            let key = data["key"];
            let value = data["value"];
            let dateStr = data["dateStr"];
            let dbSuc = yield ClubTopDao_1.ClubTopDao.updateTop(clubid, userid, key, value, dateStr);
            if (dbSuc) {
            }
            else {
                respModel.code = ErrorCode_1.ErrorCode.Code.Fail;
                respModel.msg = "修改失败";
            }
            resp.end(JSON.stringify(respModel));
        });
    }
    kill_all_users(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let respModel = new ResponseModel_1.ResponseModel();
            ServerManager_1.ServerManager.instance.kill_all_users();
            resp.end(JSON.stringify(respModel));
            setTimeout(() => __awaiter(this, void 0, void 0, function* () {
                let dbSuc = yield RoomDao_1.RoomDao.clear_all_room();
            }), 3000);
        });
    }
    get_zhanji(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let respModel = new ResponseModel_1.ResponseModel();
            let searchDate = data["searchDate"];
            let tempDate = new Date(searchDate);
            let startDate = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate());
            let pagenum = data["pagenum"];
            let pagesize = data["pagesize"];
            let userid = data["userid"];
            let gameType = data["gameType"];
            let result = yield RoomResultDao_1.RoomResultDao.getResultByGameTypeAndUserid(gameType, userid, pagenum, pagesize, startDate.getTime());
            respModel.data = result;
            resp.end(JSON.stringify(respModel));
        });
    }
    get_zhanji_detail(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
            let respModel = new ResponseModel_1.ResponseModel();
            let gameResultId = data["gameResultId"];
            let result = yield RoomVideoDao_1.RoomVideoDao.getByGameResultId(gameResultId);
            respModel.data = result;
            resp.end(JSON.stringify(respModel));
        });
    }
    on_unbind(req, resp, data, ip) {
        return __awaiter(this, void 0, void 0, function* () {
        });
    }
}
exports.GmReqHandler = GmReqHandler;
GmReqHandler.instance = new GmReqHandler();
